<template>
  <el-container class="container">
    <el-aside width="200px">
      <img src="../../img/logo.png" alt="" class="img" />
      <el-menu
        background-color="#343744"
        text-color="#fff"
        active-text-color="#ffd04b"
        unique-opened
        router
        :default-active="activePath"
      >
        <el-menu-item index="users" @click="active('users')">
          <i class="iconfont icon-yuangongguanli"></i>
          <span @click="getText">员工管理</span>
        </el-menu-item>
        <el-submenu index="2">
          <template slot="title">
            <i class="iconfont icon-diancandingdan"></i>
            <span>校园点餐</span>
          </template>
          <el-menu-item index="shop" @click="active('shop')">
            <template slot="title">
              <i class="iconfont icon-shangjia"></i>
              <span @click="getText">商家管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="mealsClassify" @click="active('mealsClassify')">
            <template slot="title">
              <i class="iconfont icon-icon_category"></i>
              <span @click="getText">分类管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="meals" @click="active('meals')">
            <template slot="title">
              <i class="iconfont icon-diancanshezhi"></i>
              <span @click="getText">菜品管理</span>
            </template>
          </el-menu-item>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="iconfont icon-dingdanguanli"></i>
            <span>订单管理</span>
          </template>
          <el-menu-item index="mealsOrder" @click="active('mealsOrder')">
            <template slot="title">
              <i class="iconfont icon-diancandingdan"></i>
              <span @click="getText">点餐订单</span>
            </template>
          </el-menu-item>
          <el-menu-item index="repairOrder" @click="active('repairOrder')">
            <template slot="title">
              <i class="iconfont icon-baoxiu"></i>
              <span @click="getText">报修订单</span>
            </template>
          </el-menu-item>
        </el-submenu>
        <el-menu-item index="notice" @click="active('notice')">
          <i class="iconfont icon-jinruluntan"></i>
          <span @click="getText">公告管理</span>
        </el-menu-item>
        <el-menu-item index="job" @click="active('job')">
          <i class="iconfont icon-renlizhaopin"></i>
          <span @click="getText">兼职管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div class="header">
          <div class="header-left">{{ headerName }}</div>
          <div class="header-right">
            <span class="header-right-title" v-if="info.power === 1"
              >超级管理员</span
            >
            <span class="header-right-title" v-if="info.power === 0"
              >管理员</span
            >
            <i
              class="iconfont icon-h"
              style="font-size: 20px"
              @click="logout"
            ></i>
          </div>
        </div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name:'index',
  data() {
    return {
      headerName: "员工管理",
      info: [],
      activePath: "",
    };
  },

  mounted(){
    this.info = JSON.parse(localStorage.getItem("userinfo"));
  },
  //创建钩子函数，页面刷新时从localStorage中获取用户信息
  created() {
    this.activePath = window.sessionStorage.getItem("activePath");
  },

  methods: {
    getText: function (e) {
      this.headerName = e.target.innerText;
    },
    logout() {
      window.localStorage.clear();
      window.sessionStorage.clear()
      this.$router.push("/login");
    },
    active(path) {
      window.sessionStorage.setItem("activePath", path);
      this.activePath = path;
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  height: 100%;
}
.el-aside {
  background-color: #343744;
  height: 100%;
  .el-menu {
    border-right: none;
  }
}
.img {
  width: 150px;
  margin: 25px;
}
.iconfont {
  margin-right: 10px;
}
.el-header {
  background-color: #ffffff;
  .header {
    display: flex;
    justify-content: space-between;
    line-height: 60px;
    .header-left {
      font-size: 16px;
      font-weight: bold;
    }
    .header-right {
      .header-right-title {
        margin-right: 10px;
        font-size: 14px;
        padding-bottom: 2px;
      }
    }
  }
}
.el-main {
  background-color: #f3f4f7;
}
</style>
